﻿Public Class OtherFunction

    Private Sub btnInstall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInstall.Click, btn垃圾清理.Click
        Try
            Dim strpath As String = System.IO.Path.Combine(GetCurrentDirectory(), "apploc\apploc.msi")
            If System.IO.File.Exists(strpath) Then
                System.Diagnostics.Process.Start(strpath)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnJRE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnJRE.Click, btn收藏.Click, btn删除导出的网址.Click
        Dim strExportDll As String = System.IO.Path.Combine(Me.GetCurrentDirectory(), "ImportDll\SetJavaEnvirment\SetJavaEnvirment.exe")
        Dim strJava As String = System.IO.Path.Combine(Me.GetCurrentDirectory(), "jdk1.6.0")
        Dim strJavaBin As String = System.IO.Path.Combine(Me.GetCurrentDirectory(), "jdk1.6.0\bin")
        Dim strJavaLib As String = ".;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar"
        If System.IO.File.Exists(strExportDll) Then
            Using po As Process = New Process()
                po.StartInfo.FileName = strExportDll
                po.StartInfo.UseShellExecute = True
                po.StartInfo.Arguments = " " + strJava
                po.Start()
            End Using
            Return
        End If
        '             
        If System.IO.Directory.Exists(strJava) Then
            'JAVA_HOME
            'CLASSPATH
            'PATH
            Dim strPathValue As String = System.Environment.GetEnvironmentVariable("path")
            If Not strPathValue.ToLower().Contains(strJavaBin.ToLower()) Then
                strPathValue = strJavaBin + ";" + strPathValue
                System.Environment.SetEnvironmentVariable("path", strPathValue, EnvironmentVariableTarget.Machine)
            End If
            System.Environment.SetEnvironmentVariable("JAVA_HOME", strJava, EnvironmentVariableTarget.Machine)
            System.Environment.SetEnvironmentVariable("CLASSPATH", strJavaLib, EnvironmentVariableTarget.Machine)
            ShowMessageBox("设置成功")
        End If
    End Sub
End Class
